﻿using System;
using Lenic.DI.Lifetimes;

namespace Lenic.DI
{
    /// <summary>
    /// 接受通知的对象接口
    /// </summary>
    public interface INotifiedObject
    {
        /// <summary>
        /// 对象解析前事件.
        /// </summary>
        event PreprocessNotifiedObject OnBeforeResolve;

        /// <summary>
        /// 对象解析时事件.
        /// </summary>
        event ProcessNotifiedObject OnRoundResolve;

        /// <summary>
        /// 对象解析后事件.
        /// </summary>
        event PostprocessNotifiedObject OnAfterResolve;
    }

    /// <summary>
    /// 预处理接受通知的对象.
    /// </summary>
    /// <param name="lifetime">接受预处理实例对象的生成对象.</param>
    public delegate void PreprocessNotifiedObject(ILifetime lifetime);

    /// <summary>
    /// 处理接受通知的对象.
    /// </summary>
    /// <param name="lifetime">接受预处理实例对象的生成对象.</param>
    /// <param name="ex">创建对象的过程中发生的异常信息.</param>
    /// <param name="result">接受处理的一个实例对象.</param>
    /// <param name="resultType">结果显式类型.</param>
    public delegate void ProcessNotifiedObject(ILifetime lifetime, Exception ex, ref object result, Type resultType);

    /// <summary>
    /// 处理接受通知的对象.
    /// </summary>
    /// <param name="lifetime">接受预处理实例对象的生成对象.</param>
    /// <param name="ex">创建对象的过程中发生的异常信息.</param>
    /// <param name="result">接受处理的一个实例对象.</param>
    /// <param name="resultType">结果显式类型.</param>
    public delegate void PostprocessNotifiedObject(ILifetime lifetime, ExceptionInfo ex, ref object result, Type resultType);
}